/*q2LCmxM8POvl78IL0LiydsmT0Boq1KyegAbxA8dmXl8=*/
import { ajax, toast, cardCache, promptBox,metaCache} from 'nc-lightapp-front';
import { headButton,innerButton, bodyButton } from '../../../../public/components/pubUtils/buttonName';
import {
	delLine,
	copyLine,
	pasteLine,
	pasteToEndLine, generate, sendSpAndCancelSenSPPubFun, delBlankLine
} from '../../../../public/components/pubUtils/billPubUtil.js';
import { imageScan, imageView } from 'sscrp/rppub/components/image';
import { tableId, formId, billType, dataSource, pkname } from '../constants';
import { cardBodyControl } from '../../../../public/components/pubUtils/buttonvisible.js';
import { getTransferInfo } from '../../../../public/components/pubUtils/transferButtonUtil.js';
import initTemplate from './initTemplate';
import { BodyVerify, WholeVerify } from '../../../../public/components/pubUtils/arapVerifyCheck';
import arapLinkReport from '../../../../public/components/arapBillLinkReport.js';
import linkvouchar from '../../../../public/components/linkvouchar.js';
import madeBill from '../../../../public/components/madeBill.js';
import { copyBill } from '../../../../public/components/pubUtils/CopyBill/arapCopyBill';
import {
	objtypeEditable,
	dealCommisionPayField,
	billEditProperties,
	dealCommisionPayFieldBack,
	cardFieldsEditableWithResetProxy,
	checkRedType
} from '../../../../public/components/pubUtils/billFieldEditableUtil.js';
import { getContext, loginContextKeys } from '../../../../public/components/arapInitInfo/loginContext';
import { moduleEnable, IMAG, SSCIVM } from '../../../../public/components/moduleEnable.js';
import { throwSagaErrorAgency } from '../../../../public/components/pubUtils/MicroServiceSocket.js';
import { buttonClick4cmp36S3 } from '../../../../public/components/pubUtils/arap436s3utils.js';
import IndependentSettleUtil from 'sp/pub/utils/IndependentSettleUtil';
import { allocperiodruleLinkQuery,showAllocation,setAllocField,ctrAllocBtn,dealBtnVisibleForApprovalCenter} from '../../../../public/components/allocation.js';
import {refreshSmartCard} from '../../../../public/components/arapSmartCard.js';
let { getDefData, setDefData, updateCache, deleteCacheById } = cardCache;
import {updateCacheTss} from '../../../../public/components/updateTableDataTs';
export function buttonClick(props, id) {
	const { openToIndepSettle } = IndependentSettleUtil;
	let code = getContext(loginContextKeys.transtype);
	let pagecode = this.getPagecode();
	this.dataInSaga.butncode = id;
	if (this.props.getUrlParam("src") == "36S3") {
		buttonClick4cmp36S3(this, props, id);
		return;
	}
	// if(id!=headButton.Refresh){
	// 	refreshSmartCard({props,key:''});//更新智能区
	// }
	if(id==headButton.Cancel||id==headButton.Save||id==headButton.SaveAndCommit||id==headButton.Add||id==headButton.Copy){//保存/保存提交/取消
		this.checknoArray = [];
	}
	switch (id) {
		case headButton.Commit: //提交
			this.Info.tipUrl = '/nccloud/arap/arappub/commit.do';
			this.commitAndUncommit();
			break;
		case headButton.Uncommit: //收回
			this.Info.tipUrl = '/nccloud/arap/arappub/uncommit.do';
			this.commitAndUncommit();
			break;
		case headButton.Generate://生成
			generate(this)
			break;
		case headButton.SendSP://传结算
			sendSpAndCancelSenSPPubFun(this, 1)
			break;
		case headButton.CancelSendSP://取消传结算
			sendSpAndCancelSenSPPubFun(this, 2)
			break;
		case headButton.LinkAprv: //审批详情
			this.setState({ showApproveDetail: true });
			break;
		case headButton.Save:
			saveBillClick(this, '/nccloud/arap/arappub/save.do')
			// this.saveBill('/nccloud/arap/arappub/save.do');
			break;
		case headButton.TempSave:
			this.saveBill('/nccloud/arap/arappub/tempsave.do');
			break;
		case headButton.SaveAndCommit:
			saveBillClick(this, '/nccloud/arap/arappub/saveandcommit.do')
			// this.saveBill('/nccloud/arap/arappub/saveandcommit.do');
			break;
		case headButton.Add:
			//卡片新增时，将浏览态的单据主键缓存，点击取消时重新查询该主键单据
			pagecode = getDefData('sessionTradeType', dataSource);
			if (code) {
				pagecode = code;
			} else if (!pagecode) {
				pagecode = this.getPagecode();
			}
			//缓存中的交易类型和链接中交易类型不一样的话，重新加载模板
			props.setUrlParam({ status: 'add', pagecode: pagecode });
			if (pagecode != this.getPagecode()) {
				
				if (this.props.getUrlParam('srcbilltype')) {
					this.props.setUrlParam({ srcbilltype: '' });
				}
				initTemplate.call(this, this.props);
			}
			if(this.props.getUrlParam("src")){
				let src = this.props.getUrlParam('src') == 'settlement';
				if(src){
					dealCommisionPayFieldBack(this.props, this.formId, this.tableId);
				}
				
				initTemplate.call(this, this.props);
			}
			if (checkRedType(this)){
				cardFieldsEditableWithResetProxy(this);
			}
			//新增清空 来源src
			props.setUrlParam({ src: '' });
			this.initAdd();
			break;
		case headButton.Edit:
			cardBillEdit.call(this)
			break;
		case headButton.Copy:
			if (checkRedType(this)){
				cardFieldsEditableWithResetProxy(this);
			}
			copyBill(this, this.getPagecode());
			break;
		case headButton.Delete:
			promptBox({
				color: 'warning',
				title: this.state.json['paybill-000002'] /* 国际化处理： 删除*/,
				content: this.state.json['paybill-000006'] /* 国际化处理： ​确定要删除吗？*/,
				noFooter: false,
				noCancelBtn: false,
				beSureBtnName: this.state.json['paybill-000004'] /* 国际化处理： 确定*/,
				cancelBtnName: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				beSureBtnClick: this.delConfirm
			});
			break;
		case headButton.Push:
			promptBox({
				color: 'warning',
				title: '推送' ,
				content: '确定要推送吗？',
				noFooter: false,
				noCancelBtn: false,
				beSureBtnName: this.state.json['paybill-000004'] /* 国际化处理： 确定*/,
				cancelBtnName: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				beSureBtnClick: this.pushConfirm
			});
			break;
		case headButton.Cancel:
			promptBox({
				color: 'warning',
				title: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				content: this.state.json['paybill-000003'] /* 国际化处理： ​确定要取消吗？*/,
				noFooter: false,
				noCancelBtn: false,
				beSureBtnName: this.state.json['paybill-000004'] /* 国际化处理： 确定*/,
				cancelBtnName: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				beSureBtnClick: this.cancel
			});
			break;
		case headButton.Pausetrans: //挂起操作
			this.pause('/nccloud/arap/arappub/pause.do');
			break;
		case headButton.Cancelpause: //取消挂起操作
			this.pause('/nccloud/arap/arappub/cancelpause.do');
			break;
		case headButton.PrePay: //预收付
			let prePayDatas = this.props.cardTable.getCheckedRows(this.tableId);
			if (prePayDatas.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000033'] }); /* 国际化处理： 请选择表体行!*/
				return;
			}
			let prePayDatasObj = [];
			prePayDatas.forEach((val) => {
				prePayDatasObj.push(val.data.values.pk_payitem.value);
			});
			let prePayDatasdata = {
				pk_items: prePayDatasObj,
				pk_bill: this.props.getUrlParam('id'),
				ts: this.props.form.getFormItemsValue(this.formId, 'ts').value,
				pageId: this.getPagecode(),
				billType: this.billType
			};
			ajax({
				url: '/nccloud/arap/arappub/prepay.do',
				data: Object.assign(prePayDatasdata, this.dataInSaga),
				success: (res) => {
					toast({ color: 'success', content: this.state.json['paybill-000034'] }); /* 国际化处理： 预收付成功*/

					if (res.data) {
						if (res.data.head) {
							this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
						}
						if (res.data.body) {
							this.props.cardTable.setTableData(this.tableId, res.data.body[this.tableId]);
						}
					}
					let newCardData = this.props.createMasterChildData(this.getPagecode(), this.formId, this.tableId);
					updateCache(pkname, this.props.getUrlParam('id'), newCardData, this.formId, dataSource);
					updateCacheTss.call(this,{pkname,data:res.data,dataSource,tableId:this.tableId,formId:this.formId});
					this.onSelected();
				}
			});
			break;
		case headButton.RedBack: //红冲操作
			let writebackData = {
				pk_bill: this.props.getUrlParam('id'),
				ts: this.props.form.getFormItemsValue(this.formId, 'ts').value,
				pageId: this.getPagecode(),
				billType: this.billType,
				tradeType: this.getPagecode()
			};
			ajax({
				url: '/nccloud/arap/arappub/redback.do',
				data: Object.assign(writebackData, this.dataInSaga),
				success: (res) => {
					let data = res.data;
					if ('Hyperlink' == data) {
						let mess = this.state.json['paybill-000067'];
						let content = this.state.json['paybill-000062'];
						let flagMess= this.state.json['paybill-000063'];
						let div = <div onClick={intoCvredPage.bind(this, props)}>< a href="javascript:void(0)" title={flagMess}>{mess}</a></div>;
						toast({ content: content, color: 'warning', groupOperation: true, customBtnBeforeClose: div });
					} else {
						this.props.beforeUpdatePage(); //打开开关
						if (res.data.head) {
							this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
						}
						if (res.data.body) {
							this.props.cardTable.setTableData(this.tableId, res.data.body[this.tableId]);
						}
						props.setUrlParam({ status: 'add', id: this.props.getUrlParam('id'), type: 'redBack' });
						this.state.buttonfalg = true;
						this.props.cardTable.setStatus(this.tableId, 'edit');
						this.props.form.setFormStatus(this.formId, 'edit');
						this.props.form.setFormItemsDisabled(this.formId, { pk_org_v: true });
						this.props.updatePage(this.formId, this.tableId); //关闭开关
						this.toggleShow();
						this.props.button.setButtonVisible([headButton.TempSave], false);
						//红冲不允许改币种
						this.props.form.setFormItemsDisabled(formId, { pk_currtype: true });
						this.props.cardTable.setColEditableByKey(tableId, ['pk_currtype'], true);
					}
				},
				error: (res) => {
					if (!res.success) {
						toast({ color: 'danger', content: res.message });
					}
				}
			});
			break;
		case headButton.CommisionPay: //承付
			ajax({
				url: '/nccloud/arap/arappub/commisionpay.do',
				data: Object.assign({
					pk_bill: this.props.getUrlParam('id'),
					billType: this.billType,
					pageId: this.getPagecode()
				}, this.dataInSaga),
				success: (res) => {
					if (res.data) {
						this.props.beforeUpdatePage(); //打开开关
						this.props.setUrlParam({ status: 'edit' });
						this.state.buttonfalg = true;
						this.props.cardTable.setStatus(this.tableId, 'edit');
						this.props.form.setFormStatus(this.formId, 'edit');
						this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
						this.props.cardTable.setTableData(this.tableId, res.data.body[this.tableId]);
						this.props.form.setFormItemsDisabled(this.formId, { pk_org_v: true });
						//处理承付字段的编辑性
						dealCommisionPayField(this.props, this.formId, this.tableId);
						this.props.updatePage(this.formId, this.tableId); //关闭开关
						this.toggleShow();
					}
				}
			});
			break;
		case headButton.CancelCommisionPay: //取消承付
			ajax({
				url: '/nccloud/arap/arappub/cancelcommisionpay.do',
				data: Object.assign({
					pk_bill: this.props.getUrlParam('id'),
					billType: this.billType,
					pageId: this.getPagecode()
				}, this.dataInSaga),
				success: (res) => {
					if (res.data) {
						this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
						this.props.cardTable.setTableData(this.tableId, res.data.body[this.tableId]);
						this.state.buttonfalg = true;
						this.toggleShow();
						toast({
							color: 'success',
							content: this.state.json['paybill-000057']
						}); /* 国际化处理： 取消承付成功！*/
					}
				}
			});
			break;
		case headButton.MadeBill: //制单
			let madeData = [
				{
					pk_bill: props.form.getFormItemsValue(formId, 'pk_paybill').value,
					billType: this.billType,
					tradeType: props.form.getFormItemsValue(formId, 'pk_tradetype').value
				}
			];
			madeBill(this, props, madeData, '', props.getSearchParam('c'));
			break;
		case headButton.BillLinkQuery: //联查单据
			this.setState({ showBillTrack: true });
			break;
		case headButton.ConnectSettleInfo: //关联结算信息
			ajax({
				url: '/nccloud/arap/arappub/validatecmp.do',
				data: null,
				success: (res) => {
					if (res.success) {
						pagecode = getDefData('sessionTradeType', dataSource);
						if (code) {
							pagecode = code;
						} else if (!pagecode) {
							pagecode = this.getPagecode();
						}
						openToIndepSettle({
							props,
							direction: "1",
							pk_billtypecode:"F3",
							rollbackAppcode: props.getSearchParam('c'),
							rollbackPageCode: pagecode
						})
					}
				}
			});

			break;
		case headButton.LinkInformer: //到账通知
			ajax({
				url: '/nccloud/arap/arappub/linkinformer.do',
				data: Object.assign({
					pk_bill: this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
					billType: this.billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.success && res.data) {
						let length = res.data.length;
						if (length == 1) {
							props.openTo('/nccloud/resources/cmp/informer/LinkBill/card/index.html', {
								appcode: '36070AISC',
								pagecode: '36070AILLINK',
								status: 'browse',
								id: res.data[0]
							});
						} else {
							props.openTo('/nccloud/resources/cmp/informer/LinkBill/list/index.html', {
								appcode: '36070AISC',
								pagecode: '36070AICLINK',
								status: 'browse',
								ids: res.data
							});
						}
					}
				}
			});
			break;
		case headButton.LinkBal: //联查余额表
			arapLinkReport(
				this.props,
				this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
				this.billType,
				this.props.form.getFormItemsValue(this.formId, 'objtype').value,
				this.props.form.getFormItemsValue(this.formId, 'pk_org_v')
			);
			break;
		case headButton.LinkDeal: //联查处理情况
			ajax({
				url: '/nccloud/arap/arappub/linkdeal.do',
				data: Object.assign({
					pk_bill: this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
					billType: this.billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.success) {
						//打开处理情况模态框
						let data = res.data;
						this.Info.combinedExaminationData = data;
						this.handleCombined();
					}
				}
			});
			break;
		case headButton.LinkVouchar: //联查凭证
			linkvouchar(
				this,
				props,
				this.props.form.getAllFormValue(this.formId),
				this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
				this.props.getSearchParam('c')
			);
			break;
		case headButton.LinkConfer: //联查协同单据
			ajax({
				url: '/nccloud/arap/arappub/linkconfer.do',
				async: false,
				data: Object.assign({
					pk_bill: this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
					billType: this.billType
				}, this.dataInSaga),
				success: (res) => {
					let data = res.data;
					if (data) {
						props.openTo(data.url, data.condition);
					}
				}
			});
			break;
		case headButton.LinkTbb: //联查计划预算
			ajax({
				url: '/nccloud/arap/arappub/linktbb.do',
				data: Object.assign({
					pk_bill: this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value,
					billType: this.billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.success) {
						this.Info.tbbLinkSourceData = res.data;
						this.setState({
							isTbbLinkshow: true
						});
					}
				}
			});
			break;
		case headButton.LinkInvoice: //发票查看
			if (!moduleEnable(this, SSCIVM)) { //校验关联模块是否启用
				return;
			}
			invoiceLink(this);
			break;
		case headButton.InvoiceUploader: //上传电子发票
			if (!moduleEnable(this, SSCIVM)) { //校验关联模块是否启用
				return;
			}
			ajax({
				url: '/nccloud/arap/arappub/sendeleinvoice.do',
				data: {
					pk_org: 'GLOBLE00000000000000',
					eleinvoice: 'IV0001'  //电子发票initcode
				},
				success: (res) => {
					if (res.success) {
						if (res.data == '2') {
							const billId = props.getUrlParam('id');
							const billtype = this.props.form.getFormItemsValue(this.formId, 'pk_billtype').value;
							const billCode = this.props.form.getFormItemsValue(this.formId, 'billno').value;
							const pk_org = this.props.form.getFormItemsValue(this.formId, 'pk_org').value;
							const tradetype = this.props.form.getFormItemsValue(this.formId, 'pk_tradetype').value;
							const random = new Date().getTime();

							this.setState({
								sscivmInvoiceData: { billId, billtype, billCode, pk_org, tradetype, random },
								isLink:false
							});
						} else {
							toast({
								color: 'warning',
								content: this.state.json['paybill-000054']
							}); /* 国际化处理： 没有使用税务管理系统，该功能无法使用！*/
						}
					}
				}
			});

			break;
		case headButton.Refresh: //刷新
			ajax({
				url: '/nccloud/arap/arappub/cardRefresh.do',
				data: Object.assign({
					pk_bill: this.props.getUrlParam('id'),
					pageId: this.getPagecode(),
					billType: this.billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.data) {
						toast({ color: 'success', title: this.state.json['paybill-000051'] }); /* 国际化处理： 刷新成功*/
						updateCache(pkname, this.props.getUrlParam('id'), res.data, this.formId, dataSource);
						updateCacheTss.call(this,{pkname,data:res.data,dataSource,tableId:this.tableId,formId:this.formId});
						if (res.data.head) {
							this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
						}
						if (res.data.body) {
							this.props.cardTable.setTableData(this.tableId, res.data.body[this.tableId]);
						}
					} else {
						this.props.form.EmptyAllFormValue(this.formId);
						this.props.cardTable.setTableData(this.tableId, { rows: [] });
					}
					this.toggleShow('', res);
					throwSagaErrorAgency.call(this, res)
				},
				error: (res) => {
					this.props.form.EmptyAllFormValue(this.formId);
					this.props.cardTable.setTableData(this.tableId, { rows: [] });
					deleteCacheById(pkname, this.props.getUrlParam('id'), dataSource);
					this.toggleShow('', res);
					let str = res.message;
					toast({ color: 'danger', content: str });;
				}
			});
			break;
		case headButton.BodyVerify: //按表体核销
			BodyVerify(props, this.formId, this.tableId, 'pk_paybill', 'pk_payitem', this);
			break;
		case headButton.WholeVerify: //按整单核销
			WholeVerify(props, this.formId, this.tableId, 'pk_paybill', this);
			break;
		case headButton.ReceiptCheck: //影像查看pk_tradetype
			if (!moduleEnable(this, IMAG)) { //校验关联模块是否启用
				return;
			}
			if (props.getUrlParam('status') == 'add') {
				toast({ color: 'warning', content: this.state.json['paybill-000035'] }); /* 国际化处理： 单据未暂存！*/
				return;
			}
			// let pk_tradetype = this.props.form.getFormItemsValue(this.formId, 'pk_tradetype').value
			// let showData = props.createMasterChildData(pk_tradetype, formId, tableId);
			// let openShowbillid = props.getUrlParam('id');
			// imageView(showData, openShowbillid, pk_tradetype, 'iweb');
			var billInfoMap = {};

			//基础字段 单据pk,单据类型，交易类型，单据的组织
			billInfoMap.pk_billid = this.props.form.getFormItemsValue(this.formId, 'pk_paybill').value;
			billInfoMap.pk_billtype = this.props.form.getFormItemsValue(this.formId, 'pk_billtype').value;
			billInfoMap.pk_tradetype = this.props.form.getFormItemsValue(this.formId, 'pk_tradetype').value;
			billInfoMap.pk_org = this.props.form.getFormItemsValue(this.formId, 'pk_org').value;
			imageView(billInfoMap, 'iweb');

			break;
		case headButton.ReceiptScan: //影像扫描
			if (!moduleEnable(this, IMAG)) { //校验关联模块是否启用
				return;
			}
			if (props.getUrlParam('status') == 'add') {
				toast({ color: 'warning', content: this.state.json['paybill-000036'] }); /* 国际化处理： 请先 <暂存> 单据再扫描影像！*/
				return;
			}
			let tradeType = this.props.form.getFormItemsValue(this.formId, 'pk_tradetype').value;
			let allData = props.createMasterChildData(tradeType, formId, tableId);
			// let openbillid = props.getUrlParam('id');
			// imageScan(allData, openbillid, tradetype, 'iweb');

			var billInfoMap = {};
			//基础字段 单据pk,单据类型，交易类型，单据的组织
			billInfoMap.pk_billid = allData.head.head.rows[0].values.pk_paybill.value;
			billInfoMap.pk_billtype = allData.head.head.rows[0].values.pk_billtype.value;
			billInfoMap.pk_tradetype = allData.head.head.rows[0].values.pk_tradetype.value;
			billInfoMap.pk_org = allData.head.head.rows[0].values.pk_org.value;

			//影像所需 FieldMap
			billInfoMap.BillType = allData.head.head.rows[0].values.pk_tradetype.value;
			billInfoMap.BillDate = allData.head.head.rows[0].values.creationtime.value;
			billInfoMap.Busi_Serial_No = allData.head.head.rows[0].values.pk_paybill.value;
			billInfoMap.pk_billtype = allData.head.head.rows[0].values.pk_billtype.value;
			billInfoMap.OrgNo = allData.head.head.rows[0].values.pk_org.value;
			billInfoMap.BillCode = allData.head.head.rows[0].values.billno.value == undefined ? '' : allData.head.head.rows[0].values.billno.value;
			billInfoMap.OrgName = allData.head.head.rows[0].values.pk_org_v.display;
			billInfoMap.Cash = allData.head.head.rows[0].values.money.value;
            //校验制单人和操作人是否为同一人

			imageScan(billInfoMap, 'iweb');

			break;
		case 'Print': //打印
			this.onPrint();
			break;
		case 'Preview': //预览
			this.print();
			break;
		case headButton.OfficalPrint: //正式打印
			this.officalPrintOutput();
			break;
		case headButton.CancelPrint: //取消正式打印
			this.cancelPrintOutput();
			break;
		case headButton.Output: //输出
			this.printOutput();
			break;
		case headButton.ExportData: //导出
			let outbillid = props.getUrlParam('id');
			let pk_bills = [];
			pk_bills.push(outbillid);
			this.Info.selectedPKS = pk_bills; //传递主键数组,之前nc需要导出的加主键
			this.props.modal.show('exportFileModal'); //不需要导出的只执行这行代码
			if (this.state.forceRender) {
				this.setState({ forceRender: false })
			}
			break;
		case headButton.AttachManage:
			let flag = props.getUrlParam('status');
			if (
				flag == 'add' ||
				props.getUrlParam('copyFlag') == 'copy' ||
				props.getUrlParam('writebackFlag') == 'redBack'
			) {
				toast({ color: 'warning', content: this.state.json['paybill-000022'] }); /* 国际化处理： 请保存后再进行上传附件！*/
				return;
			}
			//设置附件左侧分组
			setBillConfig(this);
			this.setState({
				showUploader: true,
				target: null
			});
			break;
		case headButton.AllocperiodruleLinkQuery:
			//联查期间分摊
			allocperiodruleLinkQuery(this);
			break;
		//表体肩部的按钮操作
		case bodyButton.AddLine:
			if (this.props.form.getFormItemsValue(this.formId, 'pk_org_v').value != null) {
				let rowNum = props.cardTable.getNumberOfRows(this.tableId);
				ajax({
					url: '/nccloud/arap/paybillpub/addline.do',
					data: this.props.createMasterChildData(this.getPagecode(), this.formId, this.tableId),
					success: (res) => {
						if (res.data) {
							if (res.data.head) {
								this.props.form.setAllFormValue({ [this.formId]: res.data.head[this.formId] });
							}
							if (res.data.body) {
								this.props.cardTable.addRow(this.tableId,rowNum,res.data.body[this.tableId].rows[0].values);
								this.props.cardTable.setValByKeyAndIndex(this.tableId, rowNum, 'prepay', { display:this.prepay.display,value:this.prepay.value})
							}
						}
					}
				});
			}
			break;
		case bodyButton.DelLine: //删除
			let redBackType = this.props.form.getFormItemsValue(this.formId, 'redbacktype');
			if (redBackType && redBackType.value == 3) {
				toast({ color: 'warning', content: this.state.json['paybill-000060'] }); /* 国际化处理：取消核销并红冲生成的单据不可逆操作*/
			}
			delLine(this);
			//删行之后控制肩部按钮
			this.onSelected();
			break;
		case bodyButton.CopyLine: //复制行
			if (copyLine(this, dataSource)) {
				this.setState(
					{
						buttonfalg: false
					},
					() => {
						cardBodyControl(props, this.state.buttonfalg, this);
						let isrefund = props.form.getFormItemsValue(this.formId, 'isrefund') ? props.form.getFormItemsValue(this.formId, 'isrefund').value : false
						if (isrefund) {
							props.button.setButtonVisible(['AddLine', 'Insert_inner'], false);
						}
					}
				);
			}
			break;
		case bodyButton.PasteLine: //粘贴行
			pasteLine(this);
			break;
		case bodyButton.PasteToEndLine: //粘贴行到末尾
			pasteToEndLine(this, dataSource);
			break;
		case bodyButton.CancelLine: //行取消
			this.setState(
				{
					buttonfalg: true
				},
				() => {
					cardBodyControl(props, this.state.buttonfalg, this);
					let isrefund = props.form.getFormItemsValue(this.formId, 'isrefund') ? props.form.getFormItemsValue(this.formId, 'isrefund').value : false
					if (isrefund) {
						props.button.setButtonVisible(['AddLine', 'Insert_inner'], false);
					}
				}
			);
			//取消之后控制肩部按钮
			this.onSelected();
			break;
		case bodyButton.Allocate:
			showAllocation(this);
			break;
		default:
			let transferInfo = getTransferInfo(this, id);
			if (transferInfo) {
				ajax({
					url: '/nccloud/arap/arappub/queryrelatedapp.do',
					data: {
						billType: transferInfo.src_billtype,
						transTypes: transferInfo.transtypes
					},
					success: (res) => {
						if (res) {
							//将业务流程放入缓存
							setDefData(
								transferInfo.src_billtype + transferInfo.transtypes[0],
								'transfer.dataSource',
								transferInfo.busitypes
							);
							let dest_tradetype = getDefData('sessionTradeType', dataSource);
							if (code) {
								dest_tradetype = code;
							} else if (!dest_tradetype) {
								dest_tradetype = this.getPagecode();
							}
							let url = '/' + transferInfo.src_billtype;
							props.pushTo(url, {
								src_appcode: res.data.appcode,
								src_tradetype: transferInfo.transtypes[0], //来源交易类型
								dest_billtype: this.billType,
								dest_tradetype: dest_tradetype
							});
						}
					}
				});
			}
			break;
	}
	//控制单据联查期间分摊按钮显示
	ctrAllocBtn(this);
}

function saveBillClick(that, url) {
	//删除空白行
	let checkCardData = that.props.createMasterChildData(that.getPagecode(), that.formId, that.tableId);
	delBlankLine(that, that.tableId, that.billType, checkCardData, null);

	let result = that.props.validatePageToToast([
		{
			name: that.formId,
			type: "form",
		},
		{
			name: that.tableId,
			type: "cardTable",
		}
	]);
	if (result && !result.allPassed) {
		return;
	}

	let allRows = that.props.cardTable.getVisibleRows(that.tableId);
	let noTop = false;
	let haveTop = false;
	let rowno = [];
	for (let i = 0; i < allRows.length; i++) {
		let row = allRows[i];
		if(row.values.top_billid && row.values.top_billid.value){
			haveTop = true;
		}else{
			rowno.push(i + 1);
			noTop = true;
		}
	}
	if(noTop && haveTop){
		promptBox({
			color: 'warning',
			title: url.includes('saveandcommit') ? that.state.json['public-000293'] : that.state.json['public-000279'] /* 国际化处理： 保存*/,
			content: that.state.inlt.get('public-000280', {1: rowno.join(',')}) /* 国际化处理： 第{1}行是手工增补行，与上游系统无关联，是否继续保存？*/,
			noFooter: false,
			noCancelBtn: false,
			beSureBtnName: that.state.json['public-000076'] /* 国际化处理： 确定*/,
			cancelBtnName: that.state.json['public-000077'] /* 国际化处理： 取消*/,
			beSureBtnClick: () =>{
				that.saveBill(url)
			}
		});
	}else{
		that.saveBill(url);
	}
};

//联查发票
let invoiceLink = function (that) {
	const billId = that.props.getUrlParam('id');
	const billtype = that.props.form.getFormItemsValue(that.formId, 'pk_billtype').value;
	const billCode = that.props.form.getFormItemsValue(that.formId, 'billno').value;
	const pk_org = that.props.form.getFormItemsValue(that.formId, 'pk_org').value;
	const tradetype = that.props.form.getFormItemsValue(that.formId, 'pk_tradetype').value;
	const viewRandom = new Date().getTime();

	that.setState({
		sscivmInvoiceLinkData: { billId, billtype, billCode, pk_org, tradetype, viewRandom },
		isLink:true
	});
};

export function cardBillEdit() {
	this.props.cardTable.selectAllRows(this.tableId, false);
	let sceneType = 0;
	let scene = this.props.getUrlParam('scene');
	//获取单据编号
	let djbh = this.props.form.getFormItemsValue(this.formId, 'billno').value;
	let pk_payill = this.props.form.getFormItemsValue(this.formId, 'pk_payill').value;
	let redBackType = this.props.form.getFormItemsValue(this.formId, 'redbacktype');
	let canEdit = true;
	//来源于审批中心
	if (scene == 'approve' || scene == 'approvesce') {
		sceneType = 1;
		//判断单据是否是当前用户待审批
		ajax({
			url: '/nccloud/riart/message/list.do',
			async: false,
			data: {
				//billno: djbh,
				billid:pk_payill,
				isread: 'N'
			},
			success: (result) => {
				if (result.data) {
					if (result.data.total < 1) {
						toast({
							content: this.state.json['paybill-000031'],
							color: 'warning'
						}); /* 国际化处理： 当前单据未在审批流程中，不可进行修改操作!*/
						canEdit = false;
					}
				}
			}
		});
	}
	//来源于我的作业
	if (scene == 'zycl') {
		sceneType = 2;
		//判断单据是否是当前用户待处理
		ajax({
			url: '/nccloud/ssctp/sscbd/SSCTaskHandlePendingNumAction.do',
			async: false,
			data: {
				billno: djbh
			},
			success: (result) => {
				if (result.data) {
					if (result.data.total < 1) {
						toast({
							content: this.state.json['paybill-000032'],
							color: 'warning'
						}); /* 国际化处理： 当前单据已处理，不可进行修改操作!*/
						canEdit = false;
					}
				}
			}
		});
	}
	if (!canEdit) {
		return;
	}
	let editData = {
		pk_bill: this.props.getUrlParam('id'),
		billType: this.billType,
		sence: sceneType,
		ts:this.props.form.getFormItemsValue(this.formId, 'ts')?this.props.form.getFormItemsValue(this.formId, 'ts').value:null
	};
	ajax({
		url: '/nccloud/arap/arappub/edit.do',
		data: editData,
		success: (res) => {
			if (res.success) {
				this.props.beforeUpdatePage(); //打开开关
				this.props.controlAutoFocus(true);//修改时不要日期聚焦
				this.props.setUrlParam({ status: 'edit' });
				this.state.buttonfalg = true;
				this.props.cardTable.setStatus(this.tableId, 'edit');
				this.props.form.setFormStatus(this.formId, 'edit');
				this.props.resMetaAfterPkorgEdit();
				//处理承付字段的编辑性
				dealCommisionPayField(this.props, this.formId, this.tableId);
				//处理往来对象的可编辑性
				objtypeEditable(this.props, this.formId, this.tableId);
				if (res.data && res.data.head) {
					this.props.form.setFormItemsDisabled(this.formId, res.data.head);
					this.headBack = res.data.headBack
				}
				if (res.data && res.data.body) {
					this.props.cardTable.setColEditableByKey(this.tableId, res.data.body, true)
					this.bodyBack = res.data.body
				}
				if (this.headBack && !res.data) {
					this.props.form.setFormItemsDisabled(this.formId, this.headBack);
					this.props.cardTable.setColEditableByKey(this.tableId, this.bodyBack, false)
				}
				if (res.data.bodyBack) {
					this.props.cardTable.setColEditableByKey(this.tableId, res.data.bodyBack, true)
				}
				this.props.form.setFormItemsDisabled(this.formId, { pk_org_v: true });
				if (redBackType && redBackType.value == 3) {
					let keys = ['money_de', 'local_money_de', 'groupdebit', 'globaldebit','pk_currtype'];
					this.props.cardTable.setColEditableByKey(this.tableId, keys, true);
					this.props.form.setFormItemsDisabled(formId, { pk_currtype: true });
					
					this.props.button.setButtonVisible(['CopyLine', 'DelLine'], false);
				}
				let checknoObj = this.props.cardTable.getColValue(this.tableId,'checkno');
				for(let i = 0;i<checknoObj.length;i++){
					if(checknoObj[i]){
						this.checknoArray.push(checknoObj[i].value);
					}
				}
				if(res.data&&res.data.isFrom36S3){
					this.props.setUrlParam({srcFrom36S3:'36S3'})
				}
				//设置分摊字段属性
				setAllocField(this);
				this.toggleShow('','res');
				dealBtnVisibleForApprovalCenter(this);
				//止付红冲和取消核销并红冲的单据，修改时隐藏“分摊按钮”
				if (redBackType && (redBackType.value == 3||redBackType.value == 1||redBackType.value == 2)) {
					this.props.button.setButtonVisible(['Allocate'], false);
				}
				this.props.cardTable.setColEditableByKey(this.tableId,['billrangestart','billrangeend'], false);
				this.props.updatePage(this.formId, this.tableId); //关闭开关
			}
		}
	});
}

/**
 * qinwef 2022-0211
 * 加载附件管理左侧分组
 */
function setBillConfig(that) {
	let billPK = that.props.form.getFormItemsValue(that.formId, 'pk_paybill').value;
	let billno = that.props.form.getFormItemsValue(that.formId, 'billno').value;
	let billType = that.props.form.getFormItemsValue(that.formId, 'pk_billtype').value;
	let nowBillTypeName = that.state.json['paybill-000064'];
	// if(billno!=null&&billno!='undefined'&&billno!='null'&&billno!=''){
	// 	nowBillTypeName=nowBillTypeName+billno;
	// }
	//初始设置：主单据
	that.Config.billConfig = [{
		billId: billPK,
		folderName: nowBillTypeName,
		disableButton:JSON.stringify( ["fs_group_delete","fs_group_edit"]),
		showtype: "SHOWTYPE20"
	},{
		billId:billPK+"/"+that.state.json['paybill-000066'],
		folderName: that.state.json['paybill-000066'],
		disableButton: JSON.stringify( ["fs_group_add","fs_group_delete","fs_group_edit","fs_delete","fs_move","fs_edit","fs_upload"]),
		showtype: "SHOWTYPE40"
	}];
	
	//进行单据追溯，查询上游单据
	let datas = {
		"queryCondition": {
			"bill_PK": billPK,
			"bill_type": billType
		}
	};
	ajax({
		url: '/nccloud/baseapp/riart/billFlow/billFlowAction.do',
		data: datas,
		async:false,
		success: (res) => {
			let upBillInfo = res.data;
			let upBillIdList = [];
			let upBillTypeMap = new Map();
			let upBillTypeNameMap = new Map();
			let upBillnoMap = new Map();
			let upForwardMap = new Map();
			if (upBillInfo != null && upBillInfo.length > 0) {
				for (let i = 0; i < upBillInfo.length; i++) {
					let isForward = upBillInfo[i].isForward;
					let billId = upBillInfo[i].lightBillVO.billID;
					let billTypeName = upBillInfo[i].lightBillVO.billTypeName;
					let billType = upBillInfo[i].lightBillVO.billType;
					let billno= upBillInfo[i].lightBillVO.billCode;
					if (billId != null&&billPK!=billId&&isForward<0) {
						upBillIdList.push(billId);
						upBillTypeMap.set(billId, billType);
						upBillTypeNameMap.set(billId, billTypeName);
						upBillnoMap.set(billId,billno);
						upForwardMap.set(isForward);
					}
				}
			}
			if (upBillIdList != null && upBillIdList.length > 0) {
				for(let j=0;j<upBillIdList.length;j++){
					let pkbill=upBillIdList[j];
					let pk_billtype=upBillTypeMap.get(pkbill);
					let billcon = {
						billId: pkbill,
						folderName: upBillTypeNameMap.get(upBillIdList[j])+upBillnoMap.get(upBillIdList[j]),
						disableButton: JSON.stringify( ["fs_group_add","fs_group_delete","fs_group_edit","fs_delete","fs_move","fs_edit","fs_upload_url","fs_upload"]),
						showtype: "SHOWTYPE40"
					};
					that.Config.billConfig.push(billcon);
				}
			}
		}
	})
}

//超链接进入取消核销并红冲界面方法
function intoCvredPage(props) {
	let pk_org = this.props.form.getAllFormValue(this.formId).rows[0].values['pk_org'];
	let pk_org_v = this.props.form.getAllFormValue(this.formId).rows[0].values['pk_org_v'];
	let billno = this.props.form.getAllFormValue(this.formId).rows[0].values['billno'];
	let objtype = this.props.form.getAllFormValue(this.formId).rows[0].values['objtype'];
	let billdate = this.props.form.getAllFormValue(this.formId).rows[0].values['billdate'];
	let pk_orgObj='{"display":"'+ pk_org_v.display+'","value":"'+pk_org.value+'"}';
	let billnoObj='{"display":"'+ billno.display+'","value":"'+billno.value+'"}';
	let objtypeObj='{"display":"'+ objtype.display+'","value":"'+objtype.value+'"}';
	let billdateObj='{"display":"'+ billdate.display+'","value":"'+billdate.value+'"}';
	let data='{"pk_org":'+pk_orgObj+',"billdate":'+billdateObj+',"objtype":'+objtypeObj+',"billno":'+billnoObj+'}';
	props.openTo('/nccloud/resources/arap/verificationsheet/cvred/list/index.html', {
		pk: data,
		pagecode: '20080CVRED_LIST',
		appcode: '20080CVRED',
		backflag: 'noback'
	});
}
/*q2LCmxM8POvl78IL0LiydsmT0Boq1KyegAbxA8dmXl8=*/